<template>
	<view class="content">
		<!-- <image class="bei" src="../../static/310.png" mode=""></image> -->
		<view class="name">
			<view class="namea">
				<!-- <image class="beinane" src="../../static/211.png" mode=""></image> -->
				<view class="text">
					<view class="nametext">
						<view class=""> 你好, </view>
						<view class=""> 欢迎使用 </view>
					</view>
					<view class="img">
						<image src="../../static/3113.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="logon">
			<view class="logontext"> 验证码登录 </view>
			<view class="logoncolour">
			</view>
		</view>
		<view class="title">
			<view class="titlename"> 账号 </view>
			<view class="titlein">
				<input class="uni-input" type="number" placeholder="请输入手机号" v-model="value.memberPhone" />
			</view>
		</view>
		<view class="title">
			<view class="titlename"> 验证码 </view>
			<view class="titlein">
				<input class="uni-input" password type="number" placeholder="请输入验证码" v-model="value.smsCode" />
				<view class="sending" @click="sendSmsa" v-if="type == '2'"> 获取验证码 </view>
				<view class="sending" :disabled="countdown > 0" v-if="type == '1'">
					{{ countdown > 0 ? countdown + '秒后重新获取' : '获取验证码' }}
				</view>
			</view>
		</view>
		<view class="agreement">
			<view class="titlein">
				<image v-if="hide" @click="clickb" class="confirm" src="../../static/352.png" mode=""></image>
				<image v-if="hidea" @click="clicka" class="confirm" src="../../static/350.png" mode=""></image>
				<view class="sending"> 我已阅读<text @click="useragreementa">用户协议</text>和<text
						@click="privacypolicya">隐私政策</text>并理解相关条款内容 </view>
			</view>
		</view>
		<view class="" style="display: flex;justify-content: center;margin-top: 20rpx;font-size: 24rpx;color: red;">
			用户第一次登录时自动注册 </view>
		<button class="button" @click="login">登录</button>
		<!-- <up-button text="登录" :loading="loading" @click="login" class="button"> </up-button> -->
	</view>
</template>
<script>
	import {
		appLogin,
		sendSms //获取验证码
	} from '@/request/api.js'
	export default {
		data() {
			return {
				value: {
					// loginName: '',
					// password: '',
					// captcha: '0324'
				},
				loading: false,
				show: true,
				countdown: 0,
				timer: null,
				type: '2',
				hide: false,
				hidea: true
			}
		},
		onLoad() {},
		onShow() {
			this.click()
		},
		methods: {
			privacypolicya() {
				//隐私政策
				uni.navigateTo({
					url: '/pages/index/privacypolicy'
				})
			},
			useragreementa() {
				//用户协议
				uni.navigateTo({
					url: '/pages/index/useragreement'
				})
			},
			clicka() {
				console.log('11');
				this.hide = true
				this.hidea = false
			},
			clickb() {
				this.hide = false
				this.hidea = true
			},
			sendSmsa() {
				const reg = /^1[3-9]\d{9}$/;
				if (!reg.test(this.value.memberPhone)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: "none",
					})
					return
				}
				let phone = this.value.memberPhone
				sendSms({
					phone: phone,
					type: 'LOGIN'
				}).then(res => {
					this.startCountdown()
					this.type = '1'
					if (res.code == 200) {
						console.log(res, 'reeeeeeee');
						uni.showToast({
							title: res.result,
							icon: 'none'
						})
					}
					if (res.code == 429) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				})
			},
			startCountdown() {
				if (this.countdown > 0) {
					return;
				}
				this.countdown = 60;
				this.timer = setInterval(() => {
					if (this.countdown > 0) {
						this.countdown--;
					} else {
						clearInterval(this.timer);
						this.timer = null;
						this.type = '2'
					}
				}, 1000);
			},
			beforeDestroy() {
				if (this.timer) {
					clearInterval(this.timer);
					this.timer = null;
				}
			},
			click() {
				this.show = !this.show
			},
			clicked() {
				this.show = true
			},
			dianj() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			login() {
				const reg = /^1[3-9]\d{9}$/;
				if (!reg.test(this.value.memberPhone)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: "none",
					})
					return
				}
				if (!this.value.smsCode) {
					uni.showToast({
						title: '验证码为空',
						icon: "none",
					})
					return
				}
				if (this.hide != true) {
					uni.showToast({
						title: '请勾选已阅读用户协议和隐私政策',
						icon: "none",
					})
					return
				}
				appLogin(this.value).then(res => {
					if (res.code == 500) {
						uni.showToast({
							title: res.message,
							icon: "none",
						})
					} else {
						// uni.setStorageSync('userRole', res.result.userRole)
						uni.setStorageSync('token', res.result.token)
						uni.setStorageSync('userInfo', res.result.member)
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}
				})
			},
		}
	}
</script>
<style lang="less" scoped>
	/* 在页面的<style>标签中 */
	.content {
		// text-align: center;
		padding-bottom: 60rpx;

		.bei {
			// position: fixed;
			// width: 100%;
			// height: 1144rpx;
			// top: 0;
			// left: 0;
			// z-index: -1;
		}

		.name {
			padding: 28rpx;
			// padding-top: 107rpx;
			// margin-left: 20rpx;
			background: #ff9c33;

			.namea {
				width: 702rpx;
				height: 448rpx;
				color: #333;
				font-size: 28rpx;
				font-weight: 500;
				font-style: normal;
				text-transform: none;
				text-align: center;
				position: relative;

				.beinane {
					// position: absolute;
					// top: 0;
					// left: 0;
					// width: 702rpx;
					// height: 448rpx;
					// margin-top: 10rpx;
				}

				.text {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 82rpx;
					padding-left: 54rpx;
					padding-right: 44rpx;
					padding-top: 0;

					.nametext {
						color: #ffffff;
						font-size: 48rpx;
						font-weight: 700;
						position: relative;
						z-index: 99;
					}

					.img {
						width: 366rpx;
						height: 462rpx;

						// margin-top: 90rpx;
						image {
							width: 366rpx;
							height: 462rpx;
						}
					}
				}
			}
		}

		.logon {
			width: 100%;
			padding-left: 70rpx;
			box-sizing: border-box;
			// margin-top: 54rpx;
			margin-bottom: 50rpx;
			border-radius: 64rpx;
			border-radius: 64rpx 64rpx 0rpx 0rpx;
			margin-top: -50rpx;
			// opacity: 1;
			background: #ffffff;
			padding-top: 40rpx;

			.logontext {
				color: #333333;
				font-size: 36rpx;
				font-weight: 700;
			}

			.logoncolour {
				width: 114rpx;
				height: 10rpx;
				border-radius: 190rpx;
				background: #FF9C33;
			}
		}

		.title {
			margin-left: 70rpx;
			margin-top: 42rpx;

			.titlename {
				color: #333333;
				font-size: 28rpx;
				font-weight: 700;
			}

			.titlein {
				width: 590rpx;
				height: 106rpx;
				border-radius: 252rpx;
				background: #f3f4f8;
				display: flex;
				align-items: center;
				padding-left: 48rpx;
				margin-top: 32rpx;
				// padding-right: 30rpx;
				box-sizing: border-box;

				.uni-input {
					color: #9e9e9e;
					font-size: 24rpx;
					font-weight: 400;
				}

				.sending {
					color: #ff9c33;
					font-size: 24rpx;
					font-weight: 700;
					margin-left: 40rpx;
				}
			}
		}

		.button {
			margin-top: 70rpx;
			width: 580rpx;
			height: 106rpx;
			border-radius: 252rpx;
			line-height: 106rpx;
			background: #FF9C33;
			color: #ffffff;
			font-size: 32rpx;
			font-weight: 700;
		}
	}

	.agreement {
		margin-left: 80rpx;
		margin-top: 42rpx;

		.titlein {
			display: flex;
			align-items: center;

			.confirm {
				width: 20rpx;
				height: 20rpx;
				margin-right: 10rpx;
			}

			.sending {
				color: #9e9e9e;
				font-size: 24rpx;
				font-weight: 400;

				text {
					color: #ff9c33;
				}
			}
		}
	}
</style>